var express = require('express');
var router = express.Router();

function jsonData(code, d, msg) {
	return ({error_code: code, data: d, msg: msg});
}
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express1' });
});
router.all("/test", function (req, res, next) {
	res.header("Access-Control-Allow-Credentials","true");
	res.header("Access-Control-Allow-Origin", req.headers.origin);
	res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	res.header('Access-Control-Allow-Headers', 'Content-Type');
	res.json(jsonData(0, {a:1} ));
});


module.exports = router;
